package cn.stylefeng.guns.sys.modular.system.controller;

import cn.stylefeng.guns.base.auth.annotion.Permission;
import cn.stylefeng.guns.base.log.BussinessLog;
import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.sys.core.constant.Const;
import cn.stylefeng.guns.sys.core.constant.dictmap.RoleDict;
import cn.stylefeng.guns.sys.modular.system.entity.ImUser;
import cn.stylefeng.guns.sys.modular.system.entity.Role;
import cn.stylefeng.guns.sys.modular.system.service.ImUserService;
import cn.stylefeng.guns.sys.modular.system.warpper.ImUserWrapper;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Map;

@Controller
@RequestMapping("/imuser")
public class ImUserController extends BaseController {

    private static String PREFIX = "/modular/system/imuser";

    @Autowired
    private ImUserService imUserService;

    /**
     * 跳转到角色列表页面
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:30 PM
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/imuser.html";
    }

    /**
     * 跳转到添加imuser
     *
     * @author weijh
     * @Date 2020/04/06 04:28 PM
     */
    @RequestMapping(value = "/imuser_add")
    public String imuserAdd() {
        return PREFIX + "/imuser_add.html";
    }

    /**
     * 获取角色列表
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:31 PM
     */
    @Permission
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(value = "imuserName", required = false) String imuserName) {
        Page<Map<String, Object>> imUsers = this.imUserService.selectImUsers(imuserName);
        Page<Map<String, Object>> wrap = new ImUserWrapper(imUsers).wrap();
        return LayuiPageFactory.createPageInfo(wrap);
    }

    /**
     * imuser新增
     *
     * @author fengshuonan
     * @Date 2018/12/23 6:31 PM
     */
    @RequestMapping(value = "/add")
    @BussinessLog(value = "添加imuser", key = "name", dict = RoleDict.class)
    @Permission(Const.ADMIN_NAME)
    @ResponseBody
    public ResponseData add(ImUser imUser) {
        this.imUserService.addImuser(imUser);
        return SUCCESS_TIP;
    }


}
